<?php
//城市管理控制器
class Controller_Admin_City extends Controller_Form
{
    public function __construct ($req, $res)
    {
        $this->_form_type = 'city';
        $this->_list_pagesize = 10;
        parent::__construct($req, $res);
        $this->_list_where = array();

    }

    public function action_index ()
    {
        $this->action_list();
    }

    public function action_create ()
    {
        $post = $this->request->post();
        if (! empty($post))
        {
            $this->rebuild_post_data($post);
            $this->_form_data = $post;
        }
        parent::action_create();
    }

    public function action_update ($nid)
    {
        $post = $this->request->post();
        if (! empty($post))
        {
            $this->rebuild_post_data($post);
            $this->_form_data = $post;
        }
        else
        {
            $data = Form_Data::detail($this->_form_type, $nid); 
            if(isset($data['images']))
            	$data['img'] = explode('|',$data['img']);
            $this->_form_data = $data;
        }

        parent::action_update($nid);
    }
    
    public function action_detail ($nid)
    {
        $data = Form_Data::detail($this->_form_type, $nid); 
        $this->_form_data = $data;

        parent::action_detail($nid);
    }

	//重构数据
    private function rebuild_post_data (& $post)
    {
    	if(isset($post['img'])){
    		foreach($post['img'] as $v){
    			$file_name = DOCROOT.'/'.$v;
    			$image = Image::factory($file_name);
    			file_put_contents($file_name,$image->resize('1000', NULL)->render());
    		}
    		$post['img'] = implode('|', $post['img']);
    	}
    }

	// 列表数据改造
    public function list_filter_data (& $rows)
    {
        foreach ($rows as & $rs)
        {
        }
    }

	//菜单列表
    public function actions_by_list_row (& $row, & $menus)
    {
        unset($menus[0]);
        unset($menus[2]);
    }

	

}
